package com.ys.controller.web.business;

import com.ys.entity.sys.YsDict;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
import java.util.stream.Collectors;

@Controller
@RequestMapping("/web/business/tpAnalysisDailyTargetSet")
public class WebTpAnalysisDailyTargetSetController {

	/**
	 * 设置目标系数页面
	 */
	@GetMapping("/toSetCoefficient")
	public String toSetCoefficient(Model model,int setType){
		List<YsDict> list = new YsDict().setDictKey("TP_AnalysisDailyTarget_Coefficient").queryList();
		String yesSet = "";
		String noSet = "";
		if(setType==0){
			yesSet = list.stream().filter(item->item.getDictName().equals("达成目标系数")).collect(Collectors.toList()).get(0).getDictValue();
			noSet = list.stream().filter(item->item.getDictName().equals("未达成目标系数")).collect(Collectors.toList()).get(0).getDictValue();
		}else {
			yesSet = list.stream().filter(item->item.getDictName().equals("精品达成目标系数")).collect(Collectors.toList()).get(0).getDictValue();
			noSet = list.stream().filter(item->item.getDictName().equals("精品未达成目标系数")).collect(Collectors.toList()).get(0).getDictValue();
		}
		ToSetCoefficientDto dto = new ToSetCoefficientDto(setType,yesSet,noSet);
		model.addAttribute("dto", dto);
		return "business/tpAnalysisDailyTarget/toSetCoefficient";
	}
	@Data
	@AllArgsConstructor
	private static class ToSetCoefficientDto{
		private int setType;
		private String yesSet;
		private String noSet;
	}


	/**
	 * 设置日目标页面
	 */
	@GetMapping("/toSetDailyTarget")
	public String toSetDailyTarget(Model model,long id,int dailyTarget,int setType){

		ToSetDailyTargetDto dto = new ToSetDailyTargetDto(id,dailyTarget,setType);
		model.addAttribute("dto", dto);
		return "business/tpAnalysisDailyTarget/toSetDailyTarget";
	}
	@Data
	@AllArgsConstructor
	private static class ToSetDailyTargetDto{
		private long id;
		private int dailyTarget;
		private int setType;
	}

}



